/*
 * Copyright (C), 2002-2017, 苏宁易购电子商务有限公司
 * FileName: ActivityVo.java
 * Author:   15050536
 * Date:     2017年3月27日 下午4:17:56
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.suning.sawp.member.vo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.joda.time.DateTime;

import com.google.common.collect.Lists;
import com.suning.sawp.member.constant.MemberConstants;
import com.suning.sawp.member.dto.Activity;
import com.suning.sawp.member.dto.ActivityStore;
import com.suning.sawp.member.dto.StoreCate;

/**
 * 活动实体对应的vo
 *
 * @author 15050536 石键平
 */
public class ActivityVo {

	/**
	 * 活动id
	 */
	public String id;

	/**
	 * 活动名称
	 */
	public String name;

	/**
	 * 活动考核开始时间
	 */
	public String startTime;

	/**
	 * 活动考核结束时间
	 */
	public String endTime;

	/**
	 * 客户端 新建活动的时候，会用到
	 */
	private String targetAmount;

	/**
	 * 创建人工号
	 */
	private String createUser;

	/**
	 * 创建人角色 0:大区；1:分公司；2:店长
	 */
	private String creatorRole;

	/**
	 * 活动关联的门店表id
	 */
	private String activityStoreId;

	private String storeCode;

	/**
	 * 活动关联的门店
	 */
	public List<StoreVo> stores;

	/**
	 * 关联的品类
	 */
	public List<StoreCateVo> cates;

	// 基于活动考试时间的状态 （0：未开始，1：进行中，2：已结束）
	public String status = "1";

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
		if (startTime == null) {
			return;
		}
		String now = new DateTime().toString(MemberConstants.formatter);
		// 当前时间，在开始时间之前，表示活动考核还未开始
		if (now.compareTo(startTime) < 0) {
			this.setStatus("0");
		}
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
		if (endTime == null) {
			return;
		}
		String now = new DateTime().toString(MemberConstants.formatter);
		// 当前时间，在结束时间之后，表示活动考核已经结束
		if (now.compareTo(endTime) > 0) {
			this.setStatus("2");
		}
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public List<StoreVo> getStores() {
		return stores;
	}

	public void setStores(List<StoreVo> stores) {
		this.stores = stores;
	}

	public List<StoreCateVo> getCates() {
		return cates;
	}

	public void setCates(List<StoreCateVo> cates) {
		this.cates = cates;
	}

	public String getTargetAmount() {
		return targetAmount;
	}

	public void setTargetAmount(String targetAmount) {
		this.targetAmount = targetAmount;
	}

	/**
	 * 
	 * 获取活动对象
	 *
	 * @return
	 */

	public Activity getActivity() {

		Date s = DateTime.parse(startTime, MemberConstants.formatter).toDate();
		Date e = DateTime.parse(endTime, MemberConstants.formatter).toDate();
		Activity activity = new Activity(name, s, e);

		return activity;
	}

	/**
	 * 客户端新增活动提交后，调此方法获取活动关联门店
	 *
	 * @param activityId
	 * @return
	 */
	public ActivityStore getActivityStore(Long activityId, String storeCode, String storeName) {

		ActivityStore as = new ActivityStore();
		as.setStoreCode(storeCode);
		as.setActivityId(activityId);
		as.setStoreName(storeName);
		BigDecimal t = new BigDecimal(this.getTargetAmount());
		as.setTargetAmount(t);
		return as;

	}

	/**
	 * 
	 * 后台新增活动的时候，需要调用
	 *
	 * @param activityId
	 * @return
	 */
	public List<ActivityStore> getActivityStores(Long activityId) {

		// 活动关联的门店
		List<ActivityStore> activityStores = Lists.newArrayList();

		for (StoreVo storeVo : this.getStores()) {
			ActivityStore as = new ActivityStore();
			as.setActivityId(activityId);
			as.setStoreCode(storeVo.getStoreCode());
			as.setStoreName(storeVo.getStoreName());
			BigDecimal t = new BigDecimal(storeVo.getTargetAmount());
			as.setTargetAmount(t);
			activityStores.add(as);
		}

		return activityStores;
	}

	/**
	 * 
	 * 获取门店关联的品类
	 *
	 * @param activityId
	 * @return
	 */
	public List<StoreCate> getStoreCates(Long activityId, String storeCode) {

		// 活动关联的门店
		List<StoreCate> storeCates = Lists.newArrayList();

		for (StoreCateVo cate : this.getCates()) {
			StoreCate sc = new StoreCate();
			sc.setActivityId(activityId);
			sc.setStoreCode(storeCode);
			sc.setCateCode(cate.getCateCode());
			sc.setCateName(cate.getCateName());
			BigDecimal t = new BigDecimal(cate.getTargetAmount());
			sc.setTargetAmount(t);
			storeCates.add(sc);
		}

		return storeCates;
	}

	public String getCreatorRole() {
		return creatorRole;
	}

	public void setCreatorRole(String creatorRole) {
		this.creatorRole = creatorRole;
	}

	public String getActivityStoreId() {
		return activityStoreId;
	}

	public void setActivityStoreId(String activityStoreId) {
		this.activityStoreId = activityStoreId;
	}

	public String getStoreCode() {
		return storeCode;
	}

	public void setStoreCode(String storeCode) {
		this.storeCode = storeCode;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
